<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template match="/catalogue">
	<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
		<body style="font-family: calibri; font-size: 10pt;">		
			Your search results...
			<br/><br/>
			<table cellspacing="10">
					<tr>
						<td style="font-style: italic;">Title</td>
						<td style="font-style: italic;">Author</td>
						<td style="font-style: italic;">Year</td>
						<td style="font-style: italic;">ISBN</td>
						<td style="font-style: italic;">Rating</td>
					</tr>
					<tr>
						<td colspan="5"><hr/></td>
					</tr>
				<xsl:for-each select="./book">
					<tr>
						<td><xsl:value-of select="title"/></td>
						<td><xsl:value-of select="author"/></td>
						<td><xsl:value-of select="year"/></td>
						<td><xsl:value-of select="isbn"/></td>
						<td><xsl:value-of select="rating"/></td>
					</tr>
					<tr>
						<td></td>
						<td colspan="4">
							<table cellspacing="10">
								<tr>
									<td style="font-style: italic;">Comment</td>
									<td style="font-style: italic;">Rating</td>
									<td style="font-style: italic;">Author</td>
								</tr>
								<xsl:for-each select="./feedback">
								<tr>
									<td><xsl:value-of select="comment"/></td>
									<td><xsl:value-of select="rating"/></td>
									<td><xsl:value-of select="author"/></td>
								</tr>
								</xsl:for-each>
							</table>
						</td>
					</tr>
					<tr>
						<td colspan="5">
							<!-- This form needs to send the current book obj as XML doc and add
									in the feedback value into the XML doc -->
							<form name="form1" method="post" action="urlOnServerForSubmittingFeedback">
								<input type="hidden" name="bookId" value="theBookIdHereMaybe"/>
								<textarea cols="32" rows="6" name="feedback"/>
								<input type="Submit" name="submit1" value="Post Feedback"/>
							</form>
						</td>
					</tr>
					<tr>
						<td colspan="5"><hr/></td>
					</tr>
				</xsl:for-each>
			</table>
		</body>
	</html>
	</xsl:template>

	<xsl:template match="/bookSearch">
	<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
		<head>
			<script type="text/javascript">
				
				function sendSearch(formObj)
				{	
					var req = new XMLHttpRequest();

					alert(req.readyState);
					
					title = document.getElementById("title").value;
					author = document.getElementById("author").value;
					year = document.getElementById("year").value;
					isbn = document.getElementById("isbn").value;

					xmlData = '<element name="bookSearch"> 
							<annotation>
								<documentation>search for a book</documentation>
							</annotation>
							<complexType>
								<sequence>
									<element name="title" type="string" minOccurs="0">
										' + title + '
									</element>
									<element name="author" type="string" minOccurs="0">
										' + author + '	
									</element>
									<element name="year" type="integer" minOccurs="0">
										' + year + '
									</element>
									<element name="isbn" type="string" minOccurs="0">
										' + isbn + '
									</element>
								</sequence>
							</complexType>
						</element>';

					// Open a connection.
					req.open("POST", "xslClientHandler", false);
					//req.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );

					alert(req.readyState);

					// Send the content.
					req.send(xmlData);

					//alert(req.readyState);

					return true;
				}
			</script> 
		</head>
		<body style="font-family: calibri; font-size: 10pt;">		
			Enter your query details...
			<br/><br/>
			<form name="form1" method="post" onsubmit="return sendSearch(this);">
			<table cellspacing="10">
					<tr>
						<td style="font-style: italic;">Title</td>
						<td style="font-style: italic;">Author</td>
						<td style="font-style: italic;">Year</td>
						<td style="font-style: italic;">ISBN</td>
					</tr>
					<tr>
						<td colspan="5"><hr/></td>
					</tr>
					<tr>
						<td><input type="text" name="title" id="title"/></td>
						<td><input type="text" name="author" id="author"/></td>
						<td><input type="text" name="year" id="year"/></td>
						<td><input type="text" name="isbn" id="isbn"/></td>
					</tr>
				</table>
				<br/><br/>
				<input type="submit" name="submit1" value="Submit"/>
				</form>
		</body>
	</html>
	</xsl:template>

	<xsl:template match="/bookSubmission">
	<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
		<body style="font-family: calibri; font-size: 10pt;">		
			Enter the new books details...
			<br/><br/>
			<form name="form2" method="post" action="urlOnServerToSearch">
			<table cellspacing="10">
					<tr>
						<td style="font-style: italic;">Title</td>
						<td style="font-style: italic;">Author</td>
						<td style="font-style: italic;">Year</td>
						<td style="font-style: italic;">ISBN</td>
					</tr>
					<tr>
						<td colspan="5"><hr/></td>
					</tr>
					<tr>
						<td><input type="text" name="title"/></td>
						<td><input type="text" name="author"/></td>
						<td><input type="text" name="year"/></td>
						<td><input type="text" name="isbn"/></td>
					</tr>
				</table>
				<br/><br/>
				<input type="submit" name="submit1" value="Search"/>
				</form>
		</body>
	</html>
	</xsl:template>

	<xsl:template match="/response">
	<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
		<body style="font-family: calibri; font-size: 10pt;">		
			the general response needs to be implemented ...
		</body>
	</html>
	</xsl:template>
	
</xsl:stylesheet>